package com.ming.closeto.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ming.closeto.R;
import com.ming.closeto.bean.LifeStyleBean;

import java.util.List;

public class LifeStyleAdapter extends RecyclerView.Adapter<LifeStyleAdapter.ViewHolder> {

    private Context mContext;
    private LayoutInflater inflater;
    private List<LifeStyleBean> mList;

    public LifeStyleAdapter(Context mContext, List<LifeStyleBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = inflater.inflate(R.layout.layout_lifestyle_item, null);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
        LifeStyleBean bean = mList.get(position);
        viewHolder.iv_icon.setBackgroundResource(R.mipmap.ic_launcher);
        viewHolder.tv_brf.setText(bean.getBrf());
        viewHolder.tv_txt.setText(bean.getTxt());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        private ImageView iv_icon;
        private TextView tv_brf;
        private TextView tv_txt;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            iv_icon = itemView.findViewById(R.id.iv_icon);
            tv_brf = itemView.findViewById(R.id.tv_brf);
            tv_txt = itemView.findViewById(R.id.tv_txt);
        }
    }
}
